﻿/*
   Author: Tomer Paz
   games.com
   2007
*/
//the Player Data model
package monopoly.Player {
	
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.media.Sound;
	import flash.media.SoundChannel;

	public class Player extends EventDispatcher
		{
		protected var _CurrPosition:uint;
		protected var _Name:String;
		protected var _ID:uint;
		protected var _X:uint 			= 0;
		protected var _Y:uint 			= 0;
		protected var _Cash:uint 		= 0;
		protected var _Logo:String 		= null;
		protected var _FirstName:String = null;
		protected var _LastName:String  = null;
		protected var _Email:String		= null;
		protected var _City:String		= null;
		protected var _Country:String	= null;
		protected var _LangID:String	= "en";
		protected var _Age:int			= 0;
		protected var _Gender:String	= null;
		
		protected var _Visible:Boolean = false;
		protected var _Active:Boolean  = true;
		protected var _PlayerSound:playerSound;
		protected var _PlayerSoundChannel:SoundChannel;
		protected var _MoveSound:hornSound;
		
		// init vars during construction
		public function Player(Name:String, ID:uint = 0):void
			{
			_Name = Name;
			_ID = ID;
			_CurrPosition = 1;		// attached to "Home" field
			
			register_sound_objects();
			//dispatchEvent(new Event(Event.CHANGE));
			}
		
		public function set Logo(logo:String):void
			{
			_Logo = logo;
			}
		public function get Logo():String
			{
			return(_Logo);
			}
		public function set FirstName(fname:String):void
			{
			_FirstName = fname;
			}
		public function get FirstName():String
			{
			return _FirstName;
			}
		public function set LastName(lname:String):void
			{
			_LastName = lname;
			}
		public function get LastName():String
			{
			return _LastName;
			}
		public function set Email(email:String):void
			{
			_Email = email;
			}
		public function get Email():String
			{
			return _Email;
			}
		public function set City(city:String):void
			{
			_City = city;
			}
		public function get City():String
			{
			return _City;
			}
		public function set Country(country:String):void
			{
			_Country = country;
			}
		public function get Country():String
			{
			return _Country;
			}
		public function set LangID(lang_id:String):void
			{
			_LangID = lang_id;
			}
		public function get LangID():String
			{
			return _LangID;
			}
		public function set Age(age:int):void
			{
			_Age = age;
			}
		public function get Age():int
			{
			return _Age;
			}
		public function set Gender(gender:String):void
			{
			_Gender = gender;
			}
		public function get Gender():String
			{
			return _Gender;
			}
			
		public function set CurrentPosition(Position:uint):void
			{
			_CurrPosition = Position;
			}
		public function get CurrentPosition():uint
			{
			return _CurrPosition;
			}
		public function get VisibleStatus()
			{
			return _Visible;
			}
		public function set VisibleStatus(stat:Boolean)
			{
			_Visible = stat;
			dispatchEvent(new Event(Event.ADDED));
			}
		
		public function set Cash(cash:uint):void
			{
			_Cash = cash;
			dispatchEvent(new Event(Event.RESIZE));
			}
		public function get Cash():uint
			{
			return _Cash;
			}
		public function get isActive():Boolean
			{
			return _Active;
			}
		public function set Active(status:Boolean):void
			{
			_Active = status;
			}
		
		/* tell player to move x positions FW or backward (+ or -). Returns new position */
		
		public function Move(positions:int):uint
			{
			_CurrPosition += positions;
			
			return _CurrPosition;
			}
		
		public function get Name():String
			{
			return _Name;
			}
		public function set Name(Name:String):void
			{
			_Name = Name;
			}
		public function get ID():uint
			{
			return _ID;
			}
		
		/* setters and getters to be used by controller */
		
		public function set_XY(x_axis:uint, y_axis:uint):void
			{
			// only if it really changes
			if (_X != x_axis || _Y != y_axis)
				{
				_X = x_axis;
				_Y = y_axis;
				//whoever listens, please update yourself (probably PlayerView)
				dispatchEvent(new Event(Event.CHANGE));
				}
			}
		public function get X():uint
			{
			return _X;
			}
		public function get Y():uint
			{
			return _Y;
			}
			
		public override function toString():String
			{
			return _Name;
			}
		public function play_playerSound():void
			{
			_PlayerSoundChannel = _PlayerSound.play();
			}
		public function stop_playerSound():void
			{
			_PlayerSoundChannel.stop();
			}
		public function play_moveSound():void
			{
			var channel:SoundChannel = _MoveSound.play();
			}
			
		protected function register_sound_objects():void
			{
			_PlayerSound = new playerSound();
			_MoveSound	 = new hornSound();
			}
		}
}